//专家活跃
define(function () {
    var chart4 = {};
    var provinces = ['shanghai', 'hebei', 'shanxi', 'neimenggu', 'liaoning', 'jilin', 'heilongjiang', 'jiangsu', 'zhejiang', 'anhui', 'fujian', 'jiangxi', 'shandong', 'henan', 'hubei', 'hunan', 'guangdong', 'guangxi', 'hainan', 'sichuan', 'guizhou', 'yunnan', 'xizang', 'shanxi1', 'gansu', 'qinghai', 'ningxia', 'xinjiang', 'beijing', 'tianjin', 'chongqing', 'xianggang', 'aomen'];
    var provincesText = ['上海', '河北', '山西', '内蒙古', '辽宁', '吉林', '黑龙江', '江苏', '浙江', '安徽', '福建', '江西', '山东', '河南', '湖北', '湖南', '广东', '广西', '海南', '四川', '贵州', '云南', '西藏', '陕西', '甘肃', '青海', '宁夏', '新疆', '北京', '天津', '重庆', '香港', '澳门'];
    var currentIdx = 0;
    var name = provinces[currentIdx]

    var geoCoordMap = {
        '城口':  [108.6667,31.9500],
        '开州':  [108.4167,31.1833],
        '云阳':  [108.6833,30.9500],
        '巫溪':  [109.6167,31.4000],
        '奉节':  [109.5333,31.0167],
        '潼南':  [105.8000,30.1833],
        '垫江':  [107.3333,30.3333],
        '梁平':  [107.8000,30.6833],
        '万州':  [108.4000,30.7667],
        '忠县':  [108.0333,30.3000],
        '石柱':  [108.1167,29.9833],
        '大足':  [105.7000,29.7000],
        '荣昌':  [105.5833,29.4167],
        '永川':  [105.9000,29.3667],
        '万盛':  [106.9167,28.9833],
        '铜梁':  [106.0667,29.8500],
        '北碚':  [106.4500,29.8500],
        '合川':  [106.2667,29.9667],
        '渝北':  [106.6167,29.7333],
        '璧山':  [106.2167,29.5833],
      '沙坪坝':  [106.4667,29.5833],
        '江津':  [106.2500,29.2833],
        '巴南':  [106.5000,29.3333],
        '长寿':  [107.0667,29.8333],
        '涪陵':  [107.2667,29.7333],
        '丰都':  [107.7333,29.8500],
        '武隆':  [107.7500,29.3167],
        '彭水':  [108.1667,29.3000],
        '綦江':  [106.6500,29.0000],
        '酉阳':  [108.7667,28.8167],
        '秀山':  [108.9800,28.4500],
        '南川':  [107.1200,29.1700],
        '巫山':  [109.8700,31.0800],
        '黔江':  [108.7700,29.5200]
    }

    var data = [
        {
            name:'城口',
            value:10
        },
        {
            name:'开州',
            value:20
        },
        {
            name:'云阳',
            value:55
        },
        {
            name:'巫溪',
            value:23
        },
        {
            name:'奉节',
            value:100
        },
        {
            name:'潼南',
            value:27
        },
        {
            name:'垫江',
            value:70
        },
        {
            name:'梁平',
            value:112
        },
        {
            name:'万州',
            value:38
        },
        {
            name:'忠县',
            value:88
        },
        {
            name:'石柱',
            value:33
        },
        {
            name:'大足',
            value:35
        },
        {
            name:'荣昌',
            value:19
        },
        {
            name:'永川',
            value:72
        },
        {
            name:'万盛',
            value:90
        },
        {
            name:'铜梁',
            value:65
        },
        {
            name:'北碚',
            value:22
        },
        {
            name:'合川',
            value:13
        },
        {
            name:'渝北',
            value:106
        },
        {
            name:'璧山',
            value:47
        },
        {
            name:'沙坪坝',
            value:99
        },
        {
            name:'江津',
            value:36
        },
        {
            name:'巴南',
            value:47
        },
        {
            name:'长寿',
            value:30
        },
        {
            name:'涪陵',
            value:20
        },
        {
            name:'丰都',
            value:20
        },
        {
            name:'武隆',
            value:20
        },
        {
            name:'彭水',
            value:10
        },
        {
            name:'綦江',
            value:10
        },
        {
            name:'酉阳',
            value:10
        },
        {
            name:'秀山',
            value:10
        },
        {
            name:'南川',
            value:10
        },
        {
            name:'巫山',
            value:10
        },
        {
            name:'黔江',
            value:10
        }   
    ]    
    var max = 480,
        min = 9; // todo 
    var maxSize4Pin = 100,
        minSize4Pin = 20;

    chart4.convertData = function (data) {
        var res = [];
        for (var i = 0; i < data.length; i++) {
            var geoCoord = geoCoordMap[data[i].name];
            if (geoCoord) {
                res.push({
                    name: data[i].name,
                    value: geoCoord.concat(data[i].value)
                });
            }
        }
        console.log(res)
        return res;
    };

    chart4.option = {
        title: {},
        tooltip: { },
        legend: {
            orient: 'vertical',
            y: 'bottom',
            x: 'right',
            data: ['数量'],
            textStyle: {
                color: '#fff'
            }
        },
        visualMap: {//数值范围
            min: 0,
            max: 120,
            orient: 'horizontal',
            calculable: true,
            inRange: {
                color: ['#50a3ba', '#eac736', '#d94e5d']
            },
            textStyle: {
                color: '#fff'
            },
        },
        geo: {
            map: 'chongqing',
            aspectScale: 1, //长宽比
            label: {//图形上的文本标签
                show:true,
                color:'#fff',
            },
            itemStyle: {//图形样式
                areaColor: '#364DA0',
                borderColor: '#111',
            },
            emphasis:{//高亮时文本和图形的样式
                label:{
                    color:'#fff',   
                },
                itemStyle:{
                    areaColor: '#4A8FD7'
                }
            },
            layoutCenter: ['50%', '50%'],//地图位置
            zoom:1.2,
            
        },
        series: [
            {
                name: '数量:',
                type: 'scatter',//散点图
                coordinateSystem: 'geo',
                symbolSize: 36,
                itemStyle: {//散点图普通样式
                    opacity:1,//透明度
                },
                emphasis: {//散点图高亮样式
                    itemStyle: {
                        borderColor: '#fff',
                        borderWidth: 1,
                    },
                },
                label:{
                    show: true,
                    formatter: function (params) {
                        return params.data.value[2];
                    }
                },
                tooltip:{
                    formatter: function (params) {
                        return chart4.queryHoverData(params);
                        // return `${params.marker}  ${params.data.name} : ${params.data.value[2]}`
                    }
                },
                data:chart4.convertData(data),
            }
        ],
    };

    //雷达图设置
    chart4.optionx = {    
        radar: [
            {},
            {
                startAngle: 90,
                splitNumber: 4,
                shape: 'circle',
                name: {
                    formatter: '{value}',
                    color: '#ffffff'
                },
                axisLine: {
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 0.5)'
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: 'rgba(255, 255, 255, 0.5)'
                    }
                },
                indicator: [
                    { text: '1月', max: 150 },
                    { text: '2月', max: 150 },
                    { text: '3月', max: 150 },
                    { text: '4月', max: 150 },
                    { text: '5月', max: 150 },
                    { text: '6月', max: 150 },
                    { text: '7月', max: 150 },
                    { text: '8月', max: 150 },
                    { text: '9月', max: 150 },
                    { text: '10月', max: 150 },
                    { text: '11月', max: 150 },
                    { text: '12月', max: 150 },
                ],
                center: ['50%', '50%'],
                radius: 60
            }
        ],
        series: [
            {
                name: '成绩单',
                type: 'radar',
                radarIndex: 1,
                data: [
                    {
                        value: [120, 118, 130, 100, 99, 70, 120, 118, 130, 100, 99, 70],
                        name: '张三',
                        lineStyle:{
                            color: '#E5970A',
                        },
                        itemStyle: {
                            color: '#FBE3B2',
                        },
                        label: {
                            show:true,
                            normal: {
                                show: true,
                                formatter: function (params) {
                                    return params.value;
                                }
                            }
                        }
                    },
                ]
            }
        ]
    };

    chart4.queryHoverData = function (params) {//移动上去所触发的图表
        return `${params.marker} ${params.data.name} : ${params.data.value[2]}`
    }
    chart4.queryData = function ([Chart,Chartx]) {//Chartx为雷达图实例
        $.get('./src/echart/chongqing.json', function (geoJson) {
            echarts.registerMap('chongqing', geoJson);
            Chart.setOption(chart4.option);
            Chartx.setOption(chart4.optionx);
        })
    };
    return chart4;
})